Repository navigation
Add MeshGL initializer taking per-triangle original IDs - #4
Merged
Merged
Conversation
MeshGL could be built from vertices and triangles only, leaving runOriginalID empty, so every mesh became a single anonymous original. Tagging subsets of a mesh at construction time required dropping to the C++ API. The new initializer takes one original ID per triangle and folds consecutive equal IDs into runs. Manifold then reports those IDs through originalIDs, and keeps them on the surviving faces through Boolean operations, which is what runOriginalID exists for.
Owner
|
Excellent, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
MeshGLinitializer that takes oneManifold.OriginalIDper triangle:Consecutive equal IDs are folded into runs, and
runIndex/runOriginalIDare populated accordingly. The existing two-argument initializer is unchanged; the shared setup moved into a private helper.Why
runOriginalIDis the field Manifold provides for exactly this, and its own documentation says so:Today the Swift API can read those IDs but not write them.
MeshGL.runsandMeshGL.originalIDsexpose the output side, andManifold.reserveOriginalIDs(_:)hands out IDs, but there is no way to attach them to an input mesh.Manifold.asOriginal()is all-or-nothing: it stamps one fresh ID across the whole solid. So a mesh whose faces have different provenance has to be built through the raw C++ API.The case that prompted this is importing a 3MF file into Cadova. A 3MF mesh assigns a color or base material per triangle. To keep those materials attached to the right faces through later Boolean operations, each material's triangles need their own original ID at construction time. Nothing else in the Swift API can express that, and splitting the mesh per material is not an option, since the pieces are open surfaces rather than solids.
Behaviour worth knowing
Supplying IDs means the mesh states its own provenance, so Manifold does not additionally make it an original:
Manifold.originalIDreturnsnileven when every triangle carries the same ID. The IDs themselves are preserved and readable throughmeshGL().originalIDs. This mirrors the C++ behaviour, and one of the tests pins it so the distinction does not get lost.API
The initializer preconditions on
originalIDs.count == triangles.count. Runs need not be sorted by ID, and the same ID may appear in more than one run, which the tests cover.Tests
Six tests in
MeshGLOriginalIDsTests.swift, all on a small hand-built cube:ManifoldconstructionasOriginal()collapses it onto one fresh IDFull suite green locally on macOS: 87 tests.
Context
Needed by an in-progress change to Cadova that preserves colors and materials when importing 3MF models (tomasf/Cadova#2). That change cannot build until this lands and ships in a release, so I am opening this one first.